<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>字典明细管理</title>
    <#include "../common/link.ftl">
    <script type="text/javascript">
        //编辑
        $(function () {
            $(".inputBtn").click(function () {

                //弹出模态框
                $("#editModal").modal("show");
                //修改模态框标题
                $(".modal-title").html("数据字典添加");
                //数据复原
                $("#editForm")[0].reset();

                //把目录的名字想和知道模态框中
                $('#parentName').val($('a[data-id=${qo.parentId}]').text())
                //给隐藏的INPUT赋值
                $('#parentId').val(${qo.parentId});
                //数据字典回显数据
                var data = $(this).data("json");
                if(data){
                   /* $(".modal-title").html("数据字典编辑");*/
                    $("input[name='id']").val(data.id);
                    $("input[name='title']").val(data.title);
                    $("input[name='sequence']").val(data.sequence);
                }
            })
        })

        //提交编辑表单
        $(function () {
            $(".btn_submit").click(function () {
                $("#editForm").ajaxSubmit(function (data) {
                    if(data.success){
                        $.messager.confirm("温馨提示", "操作成功", function () {
                            window.location.reload();
                        })
                    }else{
                        $.messager.alert("温馨提示", data.msg)
                    }
                })
            })
        })
        /*删除*/
        $(function () {
            $(".btn-delete").click(function () {
                var id = $(this).data("id");
                //提示一个确认框
                console.log(id)
                $.messager.confirm("警告","是否确认删除",function () {
                    //发送ajax请求
                    $.get("/systemDictionaryItem/delete.do",{id:id},systemDictionaryItemMessage)
                })
            })
        })
    </script>
</head>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="systemDictionaryItem">
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>字典明细管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <div class="row" style="margin: 20px;">
                    <div class="col-xs-3">
                        <div class="panel panel-default">
                            <div class="panel-heading">字典目录</div>
                            <div class="panel-body">
                                <div class="list-group">
                                    <#list systemDictionarys as dic>
                                        <a data-id="${dic.id}" href="/systemDictionaryItem/list.do?parentId=${dic.id}"
                                           class="list-group-item">${dic.title!}</a>
                                    </#list>
                                    <#--//回显一个样式，点击哪个，哪个就背景变色。否则分不清你点的是哪个选项-->
                                    <script>
                                        $("a[data-id=${qo.parentId}]").addClass('active');
                                    </script>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-xs-9">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <!--高级查询--->
                    <form class="form-inline" id="searchForm" action="/systemDictionaryItem/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <#--每次点击字典目录是，会显示当前目录的子明细，在点击子明细下一页时，要传递parentId-->
                        <input type="hidden" name="parentId" value="${qo.parentId}">
                        <a href="JavaScript:;" class="btn btn-success inputBtn"><span class="glyphicon glyphicon-plus"></span> 添加</a>
                    </form>
                    <table class="table table-striped table-hover" >
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>标题</th>
                            <th>序号</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                       <#list (result.list)! as entity>
                           <tr>
                               <td>${entity_index+1}</td>
                               <td>${entity.title!}</td>
                               <td>${entity.sequence!'还未指定'}</td>
                               <td>
                                   <a class="btn btn-info btn-xs inputBtn" href="javascript:;" data-json='${entity.json!}'>
                                       <span class="glyphicon glyphicon-pencil"></span>编辑
                                   </a>
                                   <a href="#" data-id="${entity.id}" class="btn btn-danger btn-xs btn-delete">
                                       <span class="glyphicon glyphicon-trash"></span>  删除
                                   </a>
                               </td>
                           </tr>
                       </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>


<#--数据字典编辑模态框-->
<div class="modal fade" id="editModal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">数据字典编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/systemDictionaryItem/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" value="" name="id">
                    <div class="form-group" >
                        <label  class="col-sm-3 control-label">字典目录：</label>
                        <div class="col-sm-6">
                            <#--name="parentName"是给用户看的-->
                            <input type="text" class="form-control" id="parentName" name="parentName" value="" placeholder="请输入字典目录" readonly>
                            <#--这个是用来提交到后台传递用的-->
                            <input type="hidden" class="form-control" id="parentId" name="parentId" value="" placeholder="请输入字典目录" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">明细标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="title" value="" placeholder="请输入明细标题">
                        </div>
                    </div>

                    <div class="form-group">
                        <label  class="col-sm-3 control-label">明细序号：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control"  name="sequence" value="" placeholder="请输入明细序号">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary btn_submit" >保存</button>
                <button type="button" class="btn btn-default" data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>


</body>
</html>
